<?php
	require_once('auth.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<center>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body background="img/bg.jpg"> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Catalog</title>
<link rel="stylesheet" href="footer.css" />
<font face="Berlin Sans FB Demi" color="#357EC7" size="2">
</head>
<body><b>
<div class="wrapper">
<h1>Bine ai venit, <?php echo $_SESSION['SESS_FIRST_NAME'];?></h1>
<a href="logout.php">Logout</a>
<a href="chpass.php">Schimba parola</a>
</font>

<font face="Berlin Sans FB Demi" color="#357EC7" size="3">
<?
require_once('config.php');
//Connect to mysql server
	error_reporting (E_ALL ^ E_NOTICE);
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}
	
	echo '<br><br>';
	
	$query=mysql_query("select * from elev where nume='".$_SESSION['SESS_FIRST_NAME']."'");
	$sql=mysql_fetch_array($query);
	echo '<h1>Informatii elev</h1>';
	echo '<table border="1">';
	?>
	<table border="1">
<tr><td>Nume: </td><td><b><? echo $sql['nume'];?></b></td></tr>
<tr><td>CNP: </td><td><b><? echo $sql['cnp'] ?></b></td></tr>
<tr><td>Clasa: </td><td><b><? echo $sql['clasa'] ?></b></td></tr>
<tr><td>Email: </td><td><b><a href="mailto:<? echo $sql['email'] ?>"><? echo $sql['email'] ?></a></b></td></tr>
<tr><td>Email parinte: </td><td><b><a href="mailto:<? echo $sql['email_parinte'] ?>"><? echo $sql['email_parinte'] ?></a></b></td></tr>
<tr><td>Clasa: </td><td><b><? echo $sql['adresa'] ?></b></td></tr>
<tr><td>Nume parinte: </td><td><b><? echo $sql['nume_parinte'] ?></b></td></tr>
<tr><td>Sex: </td><td><b><? echo $sql['sex'] ?></b></td></tr>
<?
$select=mysql_query("select * from elev_has_materie where elev_id='".$sql['id']."'");
while ($result=mysql_fetch_array($select)) {
$s=explode("-",$result['abs']);
if (strtolower($s[1])=="nemotivata") {
$i++;
} else $j++;
}
?>
<tr><td>Absente nemotivate: </td><td><b><? echo $i ?></b></td></tr>
<tr><td>Absente motivate: </td><td><b><? echo $j ?></b></td></tr>
<tr><td>Medie generala: </td><td><b><? echo $sql['mediegen'] ?></b></td></tr>

</table>
<?
	$query2=mysql_query("SELECT * from materie");
    $a=array();
	$i=0;
	while ($result2=mysql_fetch_array($query2)) {
	$a[$i]=$result2['nume'];
	$i++;
}	
	
		
	echo '<br><br>';
	echo '<h1>Note</h1>';
	echo '<center>';
	echo '<table border="1"><b><tr>';
    for($x=0;$x<$i;$x++) {
		echo "<td>".$a[$x]."</td>";
	}
    echo "</tr><tr>";
	
	
	for($x=1;$x<$i+1;$x++) {
		$sql=mysql_query("select nota from note where materie_id=$x and elev_id='".$_SESSION['SESS_MEMBER_ID']."'");
		echo "<td style=\"vertical-align:top;\">";
		while ($result=mysql_fetch_array($sql)) {
			if(isset($result['nota'])){ echo $result['nota'] ."<br />"; }
		}
		echo "</td>";
	}
	echo '</tr></table>';
	echo '</center>';
	echo '<br><br>';
	echo '<h1>Medii</h1>';
	echo '<center>';
	echo '<table border="1"><b><tr>';
    for($x=0;$x<$i;$x++) {
		echo "<td>".$a[$x]."</td>";
	}
    echo '</tr><tr>';

	    for($x=1;$x<$i+1;$x++) {
	
		$sql=mysql_query("select distinct medie from medii where materie_id='".$x."' and elev_id='".$_SESSION['SESS_MEMBER_ID']."' and sem='1'");
		echo "<td style=\"vertical-align:top;\">";
		while ($result=mysql_fetch_array($sql)) {
			if(isset($result['medie'])){ echo "Semestrul I:  ".$result['medie'] ."<br />"; }
		}
		
		$sql1=mysql_query("select distinct medie from medii where materie_id=$x and elev_id='".$_SESSION['SESS_MEMBER_ID']."' and sem='2'");
		
		while ($result2=mysql_fetch_array($sql1)) {
			if(isset($result2['medie'])){ echo "Semestrul 2:  ".$result2['medie'] ."<br />";  }
		}
		echo "</td>";
		
	}
	
	echo '</tr></table>';
	echo '</center>';
	echo '<br><br>';
	echo '<h1>Absente</h1>';
	echo '<center>';
	echo '<table border="1"><b><tr>';
	echo '<table border="1"><b><tr>';
    for($x=0;$x<$i;$x++) {
		echo "<td>".$a[$x]."</td>";
	}
    echo "</tr><tr>";
  
	for($x=1;$x<$i+1;$x++) {
		$sql=mysql_query("select abs from elev_has_materie where materie_id=$x and elev_id='".$_SESSION['SESS_MEMBER_ID']."'");
		echo "<td style=\"vertical-align:top;\">";
		while ($result=mysql_fetch_array($sql)) {
			if(isset($result['abs'])){ echo $result['abs'] ."<br />"; }
		}
		echo "</td>";
	}
	echo '</tr></table>';
	?>
	</b>
	</font>
	</body>
</div>
</b>
	</center>
	</html>
